<template>
  <div class="detail-picture">
    <div v-if="pics.length">
      <div class="detail-swiper">
        <!-- <h4 class="swiper-title">生境</h4> -->
        <swiper class="el-swiper" :options="swiperOption">
          <swiper-slide v-for="url in pics" :key="url">
            <img class="swiper-image" :src="`http://36.152.9.59:8090/single_img/?url=${url}&dw=300&dh=300`" />
          </swiper-slide>
          <div class="swiper-pagination" slot="pagination"></div>
          <div class="swiper-button-prev" slot="button-prev"></div>
          <div class="swiper-button-next" slot="button-next"></div>
        </swiper>
      </div>
    </div>
    <el-empty v-else description="暂无物种图片数据"></el-empty>
  </div>
</template>

<script>
import {isValidJson} from '@/utils'
export default {
  name: "DetailPicture",
  props: {
    detail: {
      type: Object,
      default: () => ({})
    }
  },
  computed: {
    pics(){
      const dt = this.detail

      return isValidJson(dt['照片文件名'].replaceAll('\'', '"')) ? JSON.parse(dt['照片文件名'].replaceAll('\'', '"')) : []
    }
  },
  data() {
    return {
      swiperOption: {
        loop: true,
        slidesPerView: 5,
        spaceBetween: 20,
        pagination: {
          el: '.swiper-pagination',
          clickable: true
        },
        navigation: {
          nextEl: '.swiper-button-next',
          prevEl: '.swiper-button-prev'
        }
      }
    }
  },
};
</script>

<style lang="scss">
.detail-picture{

  .detail-swiper{
    .swiper-title{
      font-size: 18px;
      color: #333;
      margin-bottom: 10px;
    }
  }
}

.el-swiper{
  .swiper-slide{
    .swiper-image{
      display: block;
      width: 100%;
      border-radius: 4px;
      box-shadow: 0 0 4px rgba(0,0,0, .5);
    }
  }
  .swiper-button-prev, .swiper-button-next{
    transform: scale(0.5);
  }
  .swiper-pagination-bullet-active{
    box-shadow: 2px 2px 2px rgba(0,0,0, .5);
    background-color: #fff;
  }
}
</style>